Home:ALL Converter>Go TCP server always throwing EOF after connecting

Go TCP server always throwing EOF after connecting

Ask Time:2020-02-24T00:46:50         Author:cy8berpunk

Json Formatter

I have an Go routine running a concurrent TCP 4 server, but everytime I connect to it from via Dial, the TCP server throws an error saying only "EOF". Interestingly it is processing the first line of data, but then the connection handle throws the error.

tcp server instance:


 if err != nil {
   fmt.Println("an error occured: ")
   fmt.Println(err)
   return
 }


 defer l.Close()

 for {
   conn, err_handle := l.Accept()
   if err_handle != nil {
     fmt.Println("node err: ",err_handle)
     return
   }
   go handle_Connection(conn, topics)
 }

handle_Connection:

func handle_Connection(conn net.Conn, topics map[string][]string) {
  defer conn.Close()
  fmt.Println("client connected")

  for {
    data, err_handle := bufio.NewReader(conn).ReadString('\n')
    if err_handle != nil {
      fmt.Println("Err: ", err_handle)
      return
    }

client:

  conn, err := net.Dial("tcp4", ":"+strconv.Itoa(port))

  if err != nil {
    fmt.Println("an error occured: ")
    fmt.Println(err)
  }

Author:cy8berpunk,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60364516/go-tcp-server-always-throwing-eof-after-connecting
yy